package org.s170.servlet.HouTaiServlet;




import io.jsonwebtoken.Jwt;
import org.s170.servlet.BaseServlet;
import org.s170.utils.JwtUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author zqx
 * @date 2021-11-19
 */
@WebServlet("/admin/main")
public class AdminServlet extends BaseServlet {


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // 获取客户端发送过来的token -> "Bearer xxxxxxxxxxxxxxxxxxxxxx"
        String token = req.getHeader(JwtUtil.TOKEN_HEADER);
        String jwt = token.replace(JwtUtil.TOKEN_HEADER, "");

        // 获取payload信息
        String username = JwtUtil.getPayload(jwt, "username", String.class);

        // 模拟DAO，查询当前登录用户信息

        // 响应客户端
        print(resp, successJson(username));

    }

}
